﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OnClient
{
    public partial class Client : Form
    {
        public Client()
        {
            InitializeComponent();
        }

        OnCommon.SocketTcpClient client;
        private void button1_Click(object sender, EventArgs e)
        {
            if (client == null)
            {
                client = new OnCommon.SocketTcpClient();
                client.Connect(this.textBox1.Text, int.Parse(this.textBox2.Text));
            }
            //while (true)
            {

                client.Send("1234567890-=qwertyuiop[]\\");
                this.InvMsg(client.Receive().GetStringData());
                client.Send("1234567890-=qwertyuiop[]\\");
                this.InvMsg(client.Receive().GetStringData());
                client.Send("1234567890-=qwertyuiop[]\\");
                this.InvMsg(client.Receive().GetStringData());
                client.Send(new { gg = "ggggggggggggg", date = DateTime.Now, client = new { gg = 'r', lr = new object(), dd = 34543555L } });
                this.InvMsg(client.Receive().GetStringData());


                var filePath = @"E:\MeCode\AllProjects\socket\OnClient\bin\Debug\OnClient.exe";
                var fs = File.OpenRead(filePath);
                client.Send(fs);
                this.InvMsg(client.Receive().GetStringData());
                client.Send(Encoding.UTF8.GetBytes("asdgadsgadsgasdgag"));
                this.InvMsg(client.Receive().GetStringData());
                client.Send("1234567890-=qwertyuiop[]\\uyfghsdfhgdsfghsfhf");
                this.InvMsg(client.Receive().GetStringData());

                //var d = client.Receive();

                //Thread.Sleep(50);
            }
            //client.Dispose();
        }

        void InvMsg(string msg)
        {
            this.richTextBox2.AppendText(msg + Environment.NewLine);
            this.richTextBox2.ScrollToCaret();
            this.richTextBox2.Focus();
        }
    }
}
